package com.mdc.mansion.web.modules.pay.web;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.mdc.mansion.web.modules.system.utils.UserUtils;
import com.mdc.mansion.dataaccess.modules.system.entity.User;

import com.mdc.mansion.dataaccess.common.persistence.Page;
import com.mdc.mansion.dataaccess.modules.pay.entity.RestaurantOrderPay;
import com.mdc.mansion.core.modules.pay.RestaurantOrderPayService;
import com.mdc.mansion.web.common.web.BaseController;
/**
 * 菜品接收设置Controller
 * @author xizf
 * @version 2018-08-10
 */
@Controller
@RequestMapping(value = "${adminPath}/pay/restaurantOrderPay")
public class RestaurantOrderPayController extends BaseController {

	@Autowired
	private RestaurantOrderPayService restaurantOrderPayService;
	
	@ModelAttribute
	public RestaurantOrderPay get(@RequestParam(required=false) String id) {
		if (StringUtils.isNotBlank(id)){
			return restaurantOrderPayService.get(id);
		}else{
			return new RestaurantOrderPay();
		}
	}
	
	@RequiresPermissions("pay:restaurantOrderPay:view")
	@RequestMapping(value = {"list", ""})
	public ModelAndView list(RestaurantOrderPay restaurantOrderPay) {
		Map<String, Object> model=new HashMap<String, Object>();
		Page<RestaurantOrderPay> page = restaurantOrderPayService.findPage(restaurantOrderPay);
        model.put("page", page);
		ModelAndView modelAndView=new ModelAndView("modules/pay/restaurantOrderPayList", model);
		return modelAndView;
	}
	
	@RequiresPermissions("pay:restaurantOrderPay:view")
	@RequestMapping(value = "form")
	public ModelAndView form(RestaurantOrderPay restaurantOrderPay) {
		Map<String, Object> model=new HashMap<String, Object>();
		model.put("restaurantOrderPay", restaurantOrderPay);
		return new ModelAndView("modules/pay/restaurantOrderPayForm",model);
	}
	

	@RequiresPermissions("pay:restaurantOrderPay:edit")
	@RequestMapping(value = "save")
	public ModelAndView save(RestaurantOrderPay restaurantOrderPay,RedirectAttributes redirectAttributes) {
		User u=UserUtils.getUser();
		restaurantOrderPay.setUpdateBy(u);
		if (StringUtils.isNotBlank(restaurantOrderPay.getId())){
			restaurantOrderPayService.updateSelective(restaurantOrderPay);
		}else{
			restaurantOrderPay.setCreateBy(u);
			restaurantOrderPayService.save(restaurantOrderPay);
		}
		this.addMessage(redirectAttributes, "操作成功");
		return new ModelAndView("redirect:./list");
	}
	
	@RequiresPermissions("pay:restaurantOrderPay:edit")
	@RequestMapping(value = "delete")
	public ModelAndView delete(RestaurantOrderPay restaurantOrderPay,RedirectAttributes redirectAttributes) {
		restaurantOrderPayService.delete(restaurantOrderPay);
		this.addMessage(redirectAttributes, "操作成功");
		return new ModelAndView("redirect:./list");
	}
	
}
